package cn.tedu.javagame.ball;

import java.awt.*;

public class Brick {
    int x,y;
    static int width = 80;
    static int height = 30;
    Color color;
    public Brick(){
        this.x = 0;
        this.y = 0;
        this.color = new Color((int) (Math.random() * (256)),(int)( Math.random() * (256)),(int)( Math.random() * (256)));
    }

    public void setX(int x) {
        this.x = x;
    }

    public void setY(int y) {
        this.y = y;
    }

    public void setWidth(int width) {
        this.width = width;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    public boolean catchBall(Ball ball){
        if ((ball.x >= this.x )&&(ball.x <= this.x + width) && (ball.y-ball.length<=this.y)&&(ball.y+ball.length >= this.y)){
            if (ball.state == 0){
                ball.state = 2;
            }else if (ball.state == 1){
                ball.state = 3;
            }else if (ball.state == 2){
                ball.state = 0;
            }else if (ball.state == 3){
                ball.state = 1;
            }
            return true;
        }
        return false;
    }
}
